package com.ham.mud.commands;

import com.ham.mud.ServerConnection;
import com.ham.mud.characters.player.Player;
import com.ham.mud.rooms.Room;
import com.ham.mud.rooms.RoomService;

/**
 * Created by hlucas on Jun 29, 2011 at 3:50:09 PM
 */
public class SayCommand extends PlayerCommand {
    @Override
    public void execute(ServerConnection connection, String[] params) {
        StringBuilder sayWhat = new StringBuilder();
        for(String param : params) {
            sayWhat.append(param);
            sayWhat.append(" ");
        }
        String sayThis = sayWhat.toString().trim();
        String lastCharacter = sayThis.substring(sayThis.length() - 1, sayThis.length());

        Player player = connection.getPlayer();
        Room room = RoomService.getRoom(player.getZone(), player.getAtX(), player.getAtY());

        String type = "say";
        if(lastCharacter.equals("!")) {
            type = "exclaim";
        } else if(lastCharacter.equals("?")) {
            type = "ask";
        }

        connection.printSolo("You " + type + ", \"" + sayThis + "\"");

        String othersSee = player.getName() + " " + type + "s, \"" + sayThis + "\"";
        room.printToOthers(othersSee, connection);
    }

    @Override
    protected String getCommandName() {
        return "say";
    }
}
